using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.UI;

public class IdleUI : MonoBehaviour
{
    // public GameObject selectVideoParent;
    public GameObject[] Page;
    public Button[] selectVideo;
    public int index;

    void Start()
    {
        // selectVideo = selectVideoParent.GetComponentsInChildren<Button>();
    }

    void Update()
    {
        // 根据按键切换视频
        if (Input.GetKeyDown(KeyCode.A) || ComTrans.Instance.GetHorizontalL() == -1)
        {
            if (--index < 0) index = selectVideo.Length - 1;
        }
        if (Input.GetKeyDown(KeyCode.D) || ComTrans.Instance.GetHorizontalR() == 1)
        {
            if (++index >= selectVideo.Length) index = 0;
        }

        for (int i = 0; i < Page.Length; i++)
        {
            Page[i].SetActive(false);
        }

        if (index >= 0 && index < 4)
        {
            Page[0].SetActive(true);
        }
        else if (index >= 4 && index < 8)
        {
            Page[1].SetActive(true);
        }
        else if (index >= 8 && index < 12)
        {
            Page[2].SetActive(true);
        }
        else if (index >= 12 && index < 16)
        {
            Page[3].SetActive(true);
        }
        else if (index >= 16 && index < 20)
        {
            Page[4].SetActive(true);
        }

        // 切换显示图片
        for (int i = 0; i < selectVideo.Length; i++)
        {
            if (i == index)
            {
                selectVideo[i].GetComponent<RectTransform>().localScale = Vector3.one * 2;
                // selectVideo[i].gameObject.SetActive(true);
            }
            else
            {
                selectVideo[i].GetComponent<RectTransform>().localScale = Vector3.one * 1.5f;
                // selectVideo[i].gameObject.SetActive(false);
            }
        }
        // 开始播放视频
        if (Input.GetKeyDown(KeyCode.R) || ComTrans.Instance.GetsecSerial())
        {
            VideoPlayerController.instance.GameStart(index);
        }
    }
}
